import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // name: 'layout',//如果父路由有默认路由那么name 没有意义
    component: () => import('@/views/Layout/Layout.vue'),
    children: [
      {
        path: '', // 默认子路由
        name: 'home',
        component: () => import('@/views/Home/Home.vue')
      },
      {
        path: 'qa',
        name: 'qa',
        component: () => import('@/views/Qa/Qa.vue')
      },
      {
        path: 'video',
        name: 'video',
        component: () => import('@/views/Video/Video')
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('@/views/My/My.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    //路由懒加载
    component: () => import('@/views/Login/Login.vue')
  },
  {
    path: '/search',
    name: 'search',
    //路由懒加载
    component: () => import('@/views/Search/Search.vue')
  },
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/Article/Article.vue'),
    // 将路由动态参数映射到组件的 props 中，更推荐这种做法
    props: true
  },
  {
    path: '/user/profile',
    component: () => import('@/views/UserProfile/UserProfile.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
